package 动态规划;

public class 乘积为正数的最长子数组长度 {
//    题解：https://leetcode-cn.com/problems/maximum-length-of-subarray-with-positive-product/solution/cheng-ji-wei-zheng-shu-de-zui-chang-zi-shu-zu-ch-3/
    public int getMaxLen(int[] nums) {
        int a=0,b=0,max=0; //a是正数长度，b是负数长度
        for(int i : nums){
            if(i==0){
                a=0;
                b=0;
                continue;
            }
            if(i>0){
                a++;
                b=b==0?0:b+1;
            }
            if(i<0){
                int t=a;
                a=b==0?0:b+1;
                b=t+1;
            }
            max=Math.max(max,a);
        }
        return max;
    }
}
